package com.felight.ems.sql;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.*;

public class Database {
	static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
	static final String DB_URL = "jdbc:mysql://localhost/tukudu";
	static final String USER = "tukudu";
	static final String PASS = "root";
	
	public static int data(){
		Connection conn = null;
		Statement stm = null;
		//ResultSet rs = null;
		int result = 0;
		
		try{
			Class.forName("com.mysql.jdbc.Driver");
			conn = DriverManager.getConnection(DB_URL,USER,PASS);
			stm=conn.createStatement();
			//String selectQuery="select * from EMPLOYEE";
//			String selectQuery1="select * from EMPLOYEE where year_of_join = '2010'";
//			String selectQuery2="select * from EMPLOYEE where year_of_join between 2010 and 2013";
//			String selectQuery3="select * from EMPLOYEE where year(DOB)<=1989";
			String updateQuery="update EMPLOYEE set salary=salary+(salary*0.2) where month(year_of_join)=02";
			//String deleteQuery="delete from EMPLOYEE where year(DOB)<1953";
			result=stm.executeUpdate(updateQuery);
			System.out.println("Result : " + result);
			if(result>=1){
				System.out.println("table is updated successfully...");
			}
//			stm.executeUpdate(deleteQuery);
//		    rs=stm.executeQuery(selectQuery);
//			while(rs.next()){
//				System.out.println(rs.getString(1)+"\t"+rs.getString(2)+"\t\t"+rs.getString(3)+"\t\t"+rs.getString(4)+"\t\t"+rs.getString(5)+"\t\t"+rs.getString(6)+"\t\t"+rs.getDouble(7)+"\t\t"+rs.getInt(8)+"\t\t"+rs.getDate(9));
//				//System.out.println(rs.getString(2));
//			}
			
		}
		catch(SQLException se){
			se.printStackTrace();
		}
		catch(Exception e){
			e.printStackTrace();
		}
		finally{
			try{
				if(conn!=null)
					conn.close();
				if(stm!=null)
					stm.close();
			}
			catch(SQLException se){
				se.printStackTrace();
			}
		}
		return result;
	}
	
	public static void main(String[] args) {
		data();
	}

}
